//
//  ReplyPopView.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/4/24.
//

import Foundation
import UIKit
import JFPopup

class ReplyPopView: UIView {
    open var selectTextWith:((_ msg: String) -> ())?

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 点击确认按钮
    @objc private func confirmToggle() {
        selectTextWith?(contentTV.text)
        closeToggle()
    }
    
    @objc func closeToggle() {
        (self.getFirstViewController() as! JFPopupController).dismiss(animated: true)
    }

    func setupUI() {
        addSubview(baseV)
        baseV.snp.makeConstraints { (make) -> Void in
            make.centerX.centerY.equalToSuperview()
            make.width.equalTo(280)
            make.height.equalTo(240)
        }
        
        baseV.addSubview(titleL)
        titleL.snp.makeConstraints { (make) -> Void in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(16)
            make.left.equalToSuperview().offset(24)
            make.right.equalToSuperview().offset(-24)
        }
        
        baseV.addSubview(contentTV)
        contentTV.snp.makeConstraints { (make) -> Void in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleL.snp.bottom).offset(14)
            make.left.equalToSuperview().offset(14)
            make.right.equalToSuperview().offset(-14)
            make.height.equalTo(114)
        }
        
        addSubview(closeBtn)
        closeBtn.snp.makeConstraints { (make) in
            make.top.equalTo(contentTV.snp.bottom).offset(18)
            make.left.equalTo(baseV.snp.left).offset(15)
            make.width.equalTo(120)
            make.height.equalTo(40)
        }
        
        baseV.addSubview(confirmBtn)
        confirmBtn.snp.makeConstraints { (make) in
            make.top.equalTo(closeBtn.snp.top)
            make.right.equalTo(baseV.snp.right).offset(-15)
            make.width.equalTo(120)
            make.height.equalTo(40)
        }
        
    }
    
    lazy var baseV: UIView = {
        let v = UIView()
        v.layer.cornerRadius = 9
        v.backgroundColor = .white
        return v
    }()
    
    lazy var titleL: UILabel = {
        let l = UILabel()
        l.text = "处置回复"
        l.font = .systemFont(ofSize: 17)
        l.textColor = .black
        l.textAlignment = .center
        l.numberOfLines = 0
        return l
    }()
    
    lazy var contentTV: BSTextView = {
        let v = BSTextView()
        v.backgroundColor = .hex("#F8F8F8")
        v.placeholder = "请输入..."
        v.layer.cornerRadius = 4
        v.layer.masksToBounds = true
        v.textContainerInset = UIEdgeInsets(top: 10, left: 8, bottom: 10, right: 10)
        return v
    }()

    lazy var confirmBtn: UIButton = {
        let btn = UIButton.createPrimaryLarge("提交")
        btn.addTarget(self, action: #selector(confirmToggle), for: .touchUpInside)
        return btn
    }()
    
    lazy var closeBtn: UIButton = {
        let btn = UIButton.createDefaultLarge("取消")
        btn.addTarget(self, action: #selector(closeToggle), for: .touchUpInside)
        return btn
    }()
}
